import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _class;

import React, { PureComponent } from 'react';
import { Popconfirm, Table } from 'antd';
import { Button as ButtonPermission } from 'components/Permission';
import intl from 'utils/intl';
import { operatorRender, valueMapMeaning, enableRender } from 'utils/renderer';
import { tableScrollWidth } from 'utils/utils';
import { Bind } from 'lodash-decorators';
/**
 * 发送配置数据展示列表
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onChange - 分页查询
 * @reactProps {Boolean} loading - 数据加载完成标记
 * @reactProps {Array} dataSource - Table数据源
 * @reactProps {Object} pagination - 分页器
 * @reactProps {Number} pagination.current - 当前页码
 * @reactProps {Number} pagination.pageSize - 分页大小
 * @reactProps {Number} pagination.total - 数据总量
 * @return React.element
 */

var ListTable = (_dec = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(ListTable, _PureComponent);

  var _super = _createSuper(ListTable);

  function ListTable() {
    _classCallCheck(this, ListTable);

    return _super.apply(this, arguments);
  }

  _createClass(ListTable, [{
    key: "editOption",
    value:
    /**
     * 编辑
     * @param {object} record - 数据对象
     */
    function editOption(record) {
      this.props.onEdit(record);
    }
    /**
     * 删除
     * @param {object} record - 数据对象
     */

  }, {
    key: "deleteOption",
    value: function deleteOption(record) {
      this.props.onDelete(record);
    }
    /**
     * 查看模板内容
     * @param {object} record
     */

  }, {
    key: "viewTemplate",
    value: function viewTemplate(record) {
      var _this$props$onOpen = this.props.onOpen,
          onOpen = _this$props$onOpen === void 0 ? function (e) {
        return e;
      } : _this$props$onOpen;
      onOpen(record);
    }
    /**
     * render
     * @returns React.element
     */

  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          loading = _this$props.loading,
          _this$props$dataSourc = _this$props.dataSource,
          dataSource = _this$props$dataSourc === void 0 ? [] : _this$props$dataSourc,
          messageType = _this$props.messageType,
          path = _this$props.path;
      var columns = [{
        title: intl.get('cmsg.sendConfig.model.sendConfig.templateCode').d('模板代码'),
        dataIndex: 'templateCode',
        width: 220
      }, {
        title: intl.get('cmsg.sendConfig.model.sendConfig.templateName').d('模板名称'),
        dataIndex: 'templateName'
      }, {
        title: intl.get('cmsg.sendConfig.model.sendConfig.typeCode').d('消息类型'),
        dataIndex: 'typeCode',
        width: 120,
        render: function render(val) {
          return val && valueMapMeaning(messageType, val);
        }
      }, {
        title: intl.get('cmsg.common.view.accountCode').d('账户代码'),
        dataIndex: 'serverCode',
        width: 200
      }, {
        title: intl.get('cmsg.common.view.accountName').d('账户名称'),
        dataIndex: 'serverName',
        width: 120
      }, {
        title: intl.get('cmsg.sendConfig.model.sendConfig.tryTimes').d('重试次数'),
        dataIndex: 'tryTimes',
        width: 120
      }, {
        title: intl.get('cpaas.common.remark').d('备注'),
        dataIndex: 'remark'
      }, {
        title: intl.get('cpaas.common.status').d('状态'),
        dataIndex: 'enabledFlag',
        render: function render(val) {
          return enableRender(val);
        }
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        dataIndex: 'option',
        width: 180,
        fixed: 'right',
        render: function render(val, record) {
          var operators = [];
          operators.push({
            key: 'edit',
            ele: /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.editTemplate"),
                type: 'button',
                meaning: '消息发送配置-编辑模板'
              }],
              onClick: function onClick() {
                return _this.editOption(record);
              }
            }, intl.get('cpaas.common.button.edit').d('编辑')),
            len: 2,
            title: intl.get('cpaas.common.button.edit').d('编辑')
          }, {
            key: 'views',
            ele: /*#__PURE__*/React.createElement("a", {
              onClick: function onClick() {
                return _this.viewTemplate(record);
              }
            }, intl.get('cmsg.sendConfig.view.message.viewTemplate').d('查看模板')),
            len: 4,
            title: intl.get('cmsg.sendConfig.view.message.viewTemplate').d('查看模板')
          }, {
            key: 'delete',
            ele: /*#__PURE__*/React.createElement(Popconfirm, {
              placement: "topRight",
              title: intl.get('cpaas.common.message.confirm.delete').d('是否删除此条记录？'),
              onConfirm: function onConfirm() {
                return _this.deleteOption(record);
              }
            }, /*#__PURE__*/React.createElement(ButtonPermission, {
              type: "text",
              permissionList: [{
                code: "".concat(path, ".button.deleteTemplate"),
                type: 'button',
                meaning: '消息发送配置-删除模板'
              }]
            }, intl.get('cpaas.common.button.delete').d('删除'))),
            title: intl.get('cpaas.common.button.delete').d('删除')
          });
          return operatorRender(operators);
        }
      }];
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: "tempServerLineId",
        loading: loading,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        dataSource: dataSource,
        pagination: false
      }));
    }
  }]);

  return ListTable;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "viewTemplate", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "viewTemplate"), _class.prototype)), _class));
export { ListTable as default };